//
//  MarriagePlanCell.m
//  BaseProject
//
//  Created by mac on 2020/11/20.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "MarriagePlanCell.h"
#import "MarriagePlanModel.h"
@interface MarriagePlanCell ()
@property(nonatomic,strong)BaseAdjustButton *leftButton;
@property(nonatomic,strong)UILabel *titleLab;
@property(nonatomic,strong)UILabel *timeLab;
@property(nonatomic,strong)UIView *bottomLineView;
@end

@implementation MarriagePlanCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = WhiteColor;
    }
    return self;
}
- (void)setListModel:(MarriagePlanDataListModel *)listModel
{
    _listModel = listModel;
    self.leftButton.selected = listModel.isSelected;
    self.titleLab.attributedText = listModel.isSelected ? listModel.plansContentSelected : listModel.plansContentNormal;
    self.titleLab.width = listModel.titleWidth;
    self.titleLab.height = listModel.titleHeight;
    if ([listModel.type isEqualToString:@"1"]) {
        self.timeLab.text = listModel.overTime;
    } else {
        self.timeLab.text = @"";
    }
    self.leftButton.centerY = self.titleLab.centerY;
    [self bottomLineView];
}
#pragma mark - click
- (void)clickLeftButton:sender
{
    if ([self.delegate respondsToSelector:@selector(MarriagePlanCellBackType:backIndexPath:)]) {
        [self.delegate MarriagePlanCellBackType:0 backIndexPath:self.indexPath];
    }
}
#pragma mark - lazy懒加载
- (BaseAdjustButton *)leftButton
{
    if (!_leftButton) {
        BaseAdjustButton *button = [BaseAdjustButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:button];
        button.imageWidth = 16*ADAPTER_WIDTH;
        button.imageHeight = 17*ADAPTER_WIDTH;
        button.marginLeft = 18*ADAPTER_WIDTH;
        button.marginRight = 50*ADAPTER_WIDTH;
        button.marginTop = 13*ADAPTER_WIDTH;
        button.marginBottom = 13*ADAPTER_WIDTH;
        [button begin];
        [button setImage:[UIImage getPNGimageInBundleWithName:@"MarrayPlan_Circle_no"] forState:UIControlStateNormal];
        [button setImage:[UIImage getPNGimageInBundleWithName:@"MarrayPlan_Circle_yes"] forState:UIControlStateSelected];
        [button addTarget:self action:@selector(clickLeftButton:) forControlEvents:UIControlEventTouchUpInside];
        _leftButton = button;
    }
    return _leftButton;
}
- (UILabel *)titleLab
{
    if (!_titleLab) {
        UILabel *lab = [[UILabel alloc]init];
        [self.contentView addSubview:lab];
        lab.textAlignment = NSTextAlignmentLeft;
        lab.numberOfLines = 0;
        lab.frame = CGRectMake(42*ADAPTER_WIDTH, 12*ADAPTER_WIDTH, 220*ADAPTER_WIDTH, 20*ADAPTER_WIDTH);
        _titleLab = lab;
    }
    return _titleLab;
}
- (UILabel *)timeLab
{
    if (!_timeLab) {
        UILabel *lab = [[UILabel alloc]init];
        [self.contentView addSubview:lab];
        lab.font = [UIFont systemFontOfSize:12*ADAPTER_WIDTH weight:UIFontWeightRegular];
        lab.textColor = rgba(153, 153, 153, 1);
        lab.textAlignment = NSTextAlignmentRight;
        lab.numberOfLines = 1;
        lab.frame = CGRectMake(WIDTH - 114*ADAPTER_WIDTH, 13*ADAPTER_WIDTH, 100*ADAPTER_WIDTH, 17*ADAPTER_WIDTH);
        _timeLab = lab;
    }
    return _timeLab;
}
- (UIView *)bottomLineView
{
    if (!_bottomLineView) {
        UIView *view = [[UIView alloc]init];
        [self.contentView addSubview:view];
        view.backgroundColor = kLineColor;
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(44*ADAPTER_WIDTH);
            make.bottom.mas_equalTo(0);
            make.right.mas_equalTo(0);
            make.height.mas_equalTo(kLineHeight);
        }];
        _bottomLineView = view;
    }
    return _bottomLineView;
}
@end
